package com.heyu.cgsd.util;

public class TemperatureConvertUtils {
    private static final int DC = 0;
    private static final int DF = 1;
    private static final int DK = 2;
    private static final int DR = 3;
    private static final int DRE = 4;

    public static float convert(float input, int srcUnit, int desUnit) {
        if (srcUnit == desUnit) {
            return 1;
        }

        if (srcUnit == DC && desUnit == DF) {
            return C2F(input);
        }

        if (srcUnit == DC && desUnit == DK) {
            return C2K(input);
        }

        if (srcUnit == DC && desUnit == DR) {
            return C2R(input);
        }

        if (srcUnit == DC && desUnit == DRE) {
            return C2Re(input);
        }

        if (srcUnit == DF && desUnit == DC) {
            return F2C(input);
        }

        if (srcUnit == DF && desUnit == DK) {
            return C2K(F2C(input));
        }

        if (srcUnit == DF && desUnit == DR) {
            return C2R(F2C(input));
        }

        if (srcUnit == DF && desUnit == DRE) {
            return C2Re(F2C(input));
        }

        if (srcUnit == DK && desUnit == DC) {
            return K2C(input);
        }

        if (srcUnit == DK && desUnit == DF) {
            return C2F(K2C(input));
        }

        if (srcUnit == DK && desUnit == DR) {
            return C2R(K2C(input));
        }

        if (srcUnit == DK && desUnit == DRE) {
            return C2Re(K2C(input));
        }

        if (srcUnit == DR && desUnit == DC) {
            return R2C(input);
        }

        if (srcUnit == DR && desUnit == DF) {
            return C2F(R2C(input));
        }

        if (srcUnit == DR && desUnit == DK) {
            return C2K(R2C(input));
        }

        if (srcUnit == DR && desUnit == DRE) {
            return C2Re(R2C(input));
        }

        if (srcUnit == DRE && desUnit == DC) {
            return Re2C(input);
        }

        if (srcUnit == DRE && desUnit == DF) {
            return C2F(Re2C(input));
        }

        if (srcUnit == DRE && desUnit == DK) {
            return C2K(Re2C(input));
        }

        if (srcUnit == DRE && desUnit == DR) {
            return C2R(Re2C(input));
        }

        return 0.0f;
    }

    private static float C2F(float input) {
        return 1.8f * input + 32f;
    }

    private static float F2C(float input) {
        return (input - 32) / 1.8f;
    }

    private static float C2K(float input) {
        return input + 273.15f;
    }

    private static float K2C(float input) {
        return input - 273.15f;
    }

    private static float C2R(float input) {
        return (input + 273.15f) * 1.8f;
    }

    private static float R2C(float input) {
        return input / 1.8f - 273.15f;
    }

    private static float C2Re(float input) {
        return input * 0.8f;
    }

    private static float Re2C(float input) {
        return input / 0.8f;
    }

}
